package cn.wolfcode.plus.web.controller;

import cn.wolfcode.plus.domain.Employee;
import cn.wolfcode.plus.domain.JsonResult;
import cn.wolfcode.plus.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/LLogin")
    @ResponseBody
    public JsonResult LLogin(String username, String password, HttpSession session){
        JsonResult jsonResult = new JsonResult();
        Employee employee = employeeService.checkLogin(username, password);
        jsonResult.setMsg("登录成功");
        jsonResult.setSuccess(true);
        session.setAttribute("EMP_IN_SESSION",employee);

        List<String> expressions = employeeService.getAllPermission(employee.getId());
        session.setAttribute("EXPRESSION_IN_SESSION",expressions);


        return jsonResult;
    }




}
